package com.ruoyi.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.contract.domain.TbContract;
import com.ruoyi.contract.service.ITbContractService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同列表Controller
 * 
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/contract/contract")
public class TbContractController extends BaseController
{
    @Autowired
    private ITbContractService tbContractService;

    /**
     * 查询合同列表列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbContract tbContract)
    {
        startPage();
        List<TbContract> list = tbContractService.selectTbContractList(tbContract);
        return getDataTable(list);
    }

    /**
     * 导出合同列表列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:export')")
    @Log(title = "合同列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbContract tbContract)
    {
        List<TbContract> list = tbContractService.selectTbContractList(tbContract);
        ExcelUtil<TbContract> util = new ExcelUtil<TbContract>(TbContract.class);
        util.exportExcel(response, list, "合同列表数据");
    }

    /**
     * 获取合同列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbContractService.selectTbContractById(id));
    }

    /**
     * 新增合同列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:add')")
    @Log(title = "合同列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbContract tbContract)
    {
        return toAjax(tbContractService.insertTbContract(tbContract));
    }

    /**
     * 修改合同列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:edit')")
    @Log(title = "合同列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbContract tbContract)
    {
        return toAjax(tbContractService.updateTbContract(tbContract));
    }

    /**
     * 删除合同列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:remove')")
    @Log(title = "合同列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbContractService.deleteTbContractByIds(ids));
    }
}
